<?php/** * TravelCRM * * An open source CRM system for travel agencies * * @package		Core * @author		mazvv * @license		GNU GPLv3 (http://gplv3.fsf.org)  * @link		http://code.google.com/p/travelcrm/ *//** * Abstract controller class, base for all controllers *  * @author mazvv * @package Libraries * @subpackage Core */
abstract class Crmcontroller extends Controller{	public $a_uri_assoc = null; #	public $a_constants = array();
		public function __construct() {		parent::Controller();		# get request hash array without controller name		$this->a_uri_assoc = $this->uri->uri_to_assoc(2);				$this->lang->load('tools'); 		$this->lang->load('common');		$this->load->model('constants_model');		$constants = $this->constants_model->get_list();		foreach($constants as $constant){			$this->a_constants[$constant->code] = $constant->descr;  			}	}
		/**	 * Default method	 * 	 * Run by default, if other method not executed	 * 	 * @access protected	 * @author mazvv	 * @return void	 */
	protected function index(){		$data = array();		$data['content'] = $this->journal();		$this->load->view('layouts/main_layout', $data);	}
		/**	 * Get object type	 * 	 * @return string	 */	public function get_objtype(){		return strtoupper(get_class($this)); 		}		/**	 * Save session value	 * 	 * @access public	 * @param $name string 		name of the session item  	 * @param $value			value of session item	 * @return void	 */
	public function set_session($name, $value){		$sessionData = $this->session->userdata($this->get_orid());		$sessionData[$name] = $value; 		$this->session->set_userdata($this->get_orid(), $sessionData);		return;	}
		/**	 * Get session item	 * 	 * @access public	 * @param $name	string 		session item name	 * @return string			session item value			 */
	public function get_session($name){		#echo $this->get_orid().'<br>';		return element($name, $this->session->userdata($this->get_orid()), null);	}
		/**	 * Refresh session values	 *  	 * @return void	 */
	public function refresh_session(){		return $this->session->set_userdata($this->get_orid(), null);			}
		/**	 * Get object's identifier	 * 	 * Get unique object's identifier	 * @access public	 * @return string	 */
	public function get_orid(){		return 'obj_'.$this->menu->get_currcontroller();	}
		/**	 * Get Paging	 * 	 * Get pagination for grid in list mode	 *	 * @access public	 * @param $total_rows int 			total quan of rows in recoedset	 * @param $value_picker boolean		is this fo value picker?	 * @return string	 */
	public function get_paging($total_rows, $value_picker = False, $limit = null){		$t = $this->a_uri_assoc;		unset($t['p']);		$this->load->library('pagination');		$limit = $limit?$limit:$this->config->item('crm_grid_limit');		$config['base_url'] = $value_picker?site_url().'/'.get_currcontroller().'/vjournal/go/p/':site_url().'/'.get_currcontroller().'/p/';		$config['total_rows'] = $total_rows;		$config['uri_segment'] = count($t)*2+3;		$config['num_links'] = 10;		$config['per_page'] = $limit;		$config['first_link'] = '&lt;&lt;';		$config['last_link'] = '&gt;&gt;';		$this->pagination->initialize($config);		$data = array();		$data['pagination'] = $this->pagination->create_links();		$data['vp'] = $value_picker;		$data['p_descr'] = sprintf(lang('PAGING'), $total_rows);		return $this->load->view('standart/paging', $data, True);	}
		/**	 * Get tools	 * 	 * get available tools for current user	 * 	 * @access public	 * @return unknown_type	 */
	public function get_tools(){		return $this->menu->get_rights();	}	
	/**	 * Set sort rule	 * 	 * Save sortrule into session for current object using it's identifier	 * 	 * @access protected	 * @return void	 */	protected function sort(){		$field = element('sort', $this->a_uri_assoc, null);		if($field){			$sort = array('c'=>$field, 'r'=>'ASC');			if($oldSort = $this->get_session('sort')){				if($oldSort['c']==$field) {					$sort['r'] = ($oldSort['r']=='ASC')?'DESC':'ASC';				}			}			$this->set_session('sort', $sort);		}		$this->index();		return;	}
			protected function vsort(){		$field = element('vsort', $this->a_uri_assoc, null);		if($field){			$sort = array('c'=>$field, 'r'=>'ASC');			if($oldSort = $this->get_session('sort')){				if($oldSort['c']==$field) {					$sort['r'] = ($oldSort['r']=='ASC')?'DESC':'ASC';				}			}			$this->set_session('sort', $sort);		}		$this->vjournal();		return;	}		/**	 * Set search rule	 * 	 * Save search rule into session for object using it's identifier	 * 	 * @param $searchrule	 * @return void	 */	public function set_searchrule($searchrule){		$this->set_session('searchrule', $searchrule);		return;	}		/**	 * Remove record	 * 	 * @return void	 */	protected function remove(){		$model_name = strtolower(get_currcontroller().'_model');		if($this->$model_name->remove_items()){			$this->session->set_flashdata('remove_success', True);		} else {			$this->session->set_flashdata('remove_failed', True);		}		redirect(get_currcontroller(), 'refresh');	}		protected function vremove(){		$model_name = strtolower(get_currcontroller().'_model');		if($this->$model_name->remove_items()){			$this->session->set_flashdata('vremove_success', True);		} else {			$this->session->set_flashdata('vremove_failed', True);		}		redirect(get_currcontroller()."/vjournal/go", 'refresh');	}			/**	 * Set pager limit	 * 	 * Save pager limit for object	 * 	 * @access protected	 * @return void	 */	protected function limit(){		$limit = element('limit', $this->a_uri_assoc, null);		if($limit){			$this->set_session('limit', $limit);		}				if(element('vjournal', $this->a_uri_assoc, null)){			$uri_assoc = $this->a_uri_assoc;			unset($uri_assoc['p']);			unset($uri_assoc['limit']);			redirect(get_currcontroller().'/'.$this->uri->assoc_to_uri($uri_assoc), 'refresh');				return;		}				redirect(get_currcontroller(), 'refresh');			return;	}		public function help(){		echo "Help is under development";			}	}